import Vue from 'vue'
import Vuex from 'vuex'
import base  from '../Base.vue'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: false,
		hasLogin: false,
		token: "",
		uploadToken: '',
		/*
		* 是否展示催收订单模态框及未查看催收订单的数量
		* */
		urgeDialogFlag: false,
		urgeDialogNum: 0,
	},
	getters: {
		urgeDialogFlag: state => {
			return state.urgeDialogFlag
		},
		urgeDialogNum: state => {
			return state.urgeDialogNum
		}
	},
	mutations: {
		login(state, token) {
			state.token = token;
			uni.setStorage({//缓存用户登陆状态
			    key: 'token',
			    data: token
			})
			state.hasLogin = true;
		},
		logout(state) {
			state.token = "";
			state.hasLogin = false;
			uni.removeStorage({
			    key: 'token'
			})
		},
		setUrgeDialogFlag(state, flag) {
			state.urgeDialogFlag = flag
		},
		setUrgeDialogNum(state, num) {
			state.urgeDialogNum = num
		}

	}
})

export default store
